package com.ljfiction.book.wxapi;


import android.content.Intent;
import android.os.Bundle;

import com.ljfiction.book.R;
import com.ljfiction.book.activitys.BaseActivity;
import com.ljfiction.book.http.UserManageBean;
import com.ljfiction.book.manage.CodeManager;
import com.ljfiction.book.tools.SettingManager;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;


public class WXPayEntryActivity extends BaseActivity implements IWXAPIEventHandler {

    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);
    	api = WXAPIFactory.createWXAPI(this, Constants.APP_ID,false);
        api.handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
		api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {

	}

	@Override
	public void onResp(BaseResp resp) {
		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
			if (resp.errCode== BaseResp.ErrCode.ERR_OK){
				//UserManageBean.backgroundRiches(WXPayEntryActivity.this);
				//showToast("支付成功,若数据没有刷新请重进此页面");
				SettingManager.getInstance().saveIsfirstPurse(1);
			}
			else {
				showToast("支付失败");
			}

			goBack();
		}
	}
}